﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;

namespace DcsGauges.Config
{ 
    class ClientConfigSection : ConfigurationSection
    {
        public const string SectionName                     = "clientConfig";
        public const string ServerElementKey                = "server";

        public const string AutoConnectKey                  = "autoConnect";
        public const string ClientNameKey                   = "clientName";

        [ConfigurationProperty(ServerElementKey, IsRequired = true)]
        public ServerConfig Server
        {
            get { return (ServerConfig)this[ServerElementKey]; }
            set { this[ServerElementKey] = value; }
        }

        [ConfigurationProperty(AutoConnectKey, IsRequired = true)]
        public bool AutoConnect
        {
            get { return (bool)this[AutoConnectKey]; }
            set { this[AutoConnectKey] = value; }
        }

        [ConfigurationProperty(ClientNameKey, IsRequired = true)]
        public string ClientName
        {
            get { return (string)this[ClientNameKey]; }
            set { this[ClientNameKey] = value; }
        }
 
        private static ClientConfigSection loaded               = null;
        public static ClientConfigSection Loaded
        {
            get
            {
                if(loaded == null)
                {
                    loaded = (ClientConfigSection)ConfigurationManager.GetSection(SectionName);
                }

                return loaded;
            }
        }
    }
}
